package com.firefly.admin.common.utils;

import com.firefly.admin.common.service.CommonLogService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import javax.annotation.PostConstruct;
import javax.servlet.http.HttpServletRequest;

@Component
public class LogUtil {
    private static CommonLogService commonLogService;
    @Autowired
    private CommonLogService service;

    @PostConstruct
    public void init() {
        commonLogService = service;
    }

    /**
     * 记录登录或登出日志
     *
     * @param request        请求
     * @param methodName     方法名
     * @param operateType    操作类型，登录、登出
     * @param operateResult  操作结果
     * @param responseResult 响应结果
     * @param requestParam   请求参数
     * @param operatorName   操作人用户名
     */
    public static void saveLoginOrLogoutLog(HttpServletRequest request, String methodName, String operateType, String operateResult, String responseResult, String requestParam, String operatorName) {
        commonLogService.saveLoginOrLogoutLog(request, methodName, operateType, operateResult, responseResult, requestParam, operatorName);
    }

    /**
     * 记录操作类日志
     *
     * @param request        操作请求
     * @param operateModule  操作模块
     * @param operateType    操作类型
     * @param operateDesc    操作描述
     * @param operateMethod  操作方法
     * @param operatorId     操作人ID
     * @param operateResult  操作结果
     * @param responseResult 响应结果
     * @param requestParam   请求参数
     */
    public static void saveOperateLog(HttpServletRequest request, String operateModule, String operateType, String operateDesc, String operateMethod, Long operatorId, String operateResult, String responseResult, String requestParam) {
        commonLogService.saveOperateLog(request, operateModule, operateType, operateDesc, operateMethod, operatorId, operateResult, responseResult, requestParam);

    }

    /**
     * 系统登录记录操作日志
     *
     * @param userName 用户名
     */
    public static void saveSystemLogoutLog(String userName) {
        commonLogService.saveSystemLogoutLog(userName);
    }
}
